
package com.example.myapplication3


import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.TextView
import androidx.activity.ComponentActivity
import androidx.appcompat.app.AppCompatActivity

const val FIRST_MSG = "FIRST_MSG"
const val SECOND_MSG = "SECOND_MSG"
@Suppress("DEPRECATION")
class MainActivity : ComponentActivity() {
    private lateinit var textView: TextView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val editText = findViewById<EditText>(R.id.editText)
        val first = findViewById<Button>(R.id.first)
        val second = findViewById<Button>(R.id.second)
        val third = findViewById<Button>(R.id.third)
        val fourth = findViewById<Button>(R.id.fourth)
        textView = findViewById(R.id.textView)

        first.setOnClickListener{
            val intent = Intent(this, SecondActivity::class.java)
            val inputText = editText.text.toString() // 获取输入框内容
            intent.putExtra(FIRST_MSG, inputText)   // 传递参数
            startActivity(intent)
        }
        second.setOnClickListener {
            val intent = Intent(this, ThirdActivity::class.java)
            this.startActivityForResult(intent,0)
        }
        third.setOnClickListener {
            val intent = Intent(this,FourthActivity::class.java)
            startActivity(intent)
        }
        fourth.setOnClickListener {
            val intent = Intent(this,FifthActivity::class.java)
            startActivity(intent)
        }
    }
    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?){
        super.onActivityResult(requestCode,resultCode,data)
        if(requestCode == 0){
            if(resultCode == 1){
                textView.text = data?.getStringExtra(SECOND_MSG)
            }
        }
    }
}